# 51job
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://login.51job.com/login.php')
driver.maximize_window()
driver.find_element(By.LINK_TEXT, '密码登录').click()
driver.find_element(By.ID, 'loginname').send_keys('19849507509')
driver.find_element(By.ID, 'password').send_keys('tan094721')
driver.find_element(By.ID, 'isread_em').click()
sleep(2)
driver.find_element(By.ID, 'login_btn_withPwd').click()
sleep(10)

WebDriverWait(driver, 15).until(expected_conditions.visibility_of_element_located((By.LINK_TEXT, '职位搜索')),
                                '对不起，找不到元素！！')
driver.find_element(By.LINK_TEXT, '职位搜索').click()

WebDriverWait(driver, 15).until(expected_conditions.visibility_of_element_located((By.ID, 'search_btn')), '对不起，找不到元素！！')

driver.find_element(By.ID, 'keywordInput').send_keys('软件测试')
driver.find_element(By.ID, 'search_btn').click()

WebDriverWait(driver, 15).until(expected_conditions.visibility_of_element_located(
    (By.XPATH, '/html/body/div[2]/div[3]/div/div[1]/div[1]/span[1]/em')), '对不起，找不到元素！！')

driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/div[1]/div[1]/span[1]/em').click()

# for i in range(3,11):
#     WebDriverWait(driver,15).until(expected_conditions.visibility_of_element_located(
#         (By.XPATH, f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[2]/div/div/div/ul/li[{i}]/div'))
#         , '对不起，找不到元素！！')
#     driver.find_element(By.XPATH, f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[2]/div/div/div/ul/li[{i}]/div').click()
for i in range(1, 51):
    text = driver.find_element(By.XPATH, f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[{i}]/div[2]/a').text
    print(text)
    # if text=='华通科技有限公司':
    # document.querySelector(
    #     "body > div:nth-child(4) > div.j_result > div > div.leftbox > div:nth-child(4) > div.j_joblist > div:nth-child(3)")
    # driver.find_element(By.XPATH,f'/html/body/div[2]/div[3]/div/div[2]/div[4]/div[1]/div[{i}]').click()

# /html/body/div[2]/div[3]/div/div[2]/div[4]/div[2]/div/div/div/ul/li[2]/div
# /html/body/div[2]/div[3]/div/div[2]/div[4]/div[2]/div/div/div/ul/li[3]/a
